package businessLayer.businessObjects;

import java.util.ArrayList;

import dataAccessLayer.abstractFactory.Factory;
import dataAccessLayer.abstractFactory.daos.DAOpies;
import dataAccessLayer.abstractFactory.daos.DAOrecipes;
import dataAccessLayer.abstractFactory.daos.DAOusers;
import dataAccessLayer.visualObject.VOpie;
import dataAccessLayer.visualObject.VOrecipe;
import dataAccessLayer.visualObject.VOuser;

public class PiesBusinessObject 
{
	private DAOpies daoPies;
	private DAOrecipes daoRecipes;
	private DAOusers daoUsers;
	
	public PiesBusinessObject(Factory factory)
	{
		daoPies = factory.getDAOpies();
		daoRecipes = factory.getDAOrecipes();
		daoUsers = factory.getDAOusers();
	}

	public Object[][] getPies() 
	{
		ArrayList<VOpie> pies = daoPies.listPies();
		
		String[] recipes = new String[pies.size()];
		String[] pastryCookies = new String[pies.size()];
		
		VOrecipe vOrecipe = new VOrecipe();
		VOuser vOuser = new VOuser();
		
		for (int i = 0; i < pies.size(); i++) 
		{
			vOrecipe.setCode(pies.get(i).getRecipe());
			vOuser.setCode(pies.get(i).getPastryCook());
			
			recipes[i] = daoRecipes.searchRecipeByCode(vOrecipe).getName();
			pastryCookies[i] = daoUsers.searchUserByCode(vOuser).getFirstName()+" "+daoUsers.searchUserByCode(vOuser).getLastName();
		}
		
		Object[][] resul = new Object[pies.size()][4];
		
		for (int i = 0; i < resul.length; i++) 
		{
			resul[i][0] = pies.get(i).getName();
			resul[i][1] = recipes[i];
			resul[i][2] = pies.get(i).getPrice();
			resul[i][3] = pastryCookies[i];
		}
		
		return resul;
	}

	public Object[] searchPieDetail(String name) 
	{
		VOpie vOpie = new VOpie();
		vOpie.setName(name);
		
		vOpie = daoPies.searchPieByName(vOpie);
		
		Object[] resul = new Object[1];
		resul[0] = vOpie.getImage();
		
		return resul;
	}
}
